﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YBApproval.IDAL;
using YBApproval.BLL;
using YBApproval.Model;

namespace YBApproval
{
    public partial class MyRequestHistory : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected override void OnPreRender(EventArgs e)
        {
            //在该事件发生前：

            //Page 对象会针对每个控件和页调用 EnsureChildControls。 

            //设置了 DataSourceID 属性的每个数据绑定控件会调用 DataBind 方法。有关更多信息，请参见下面的数据绑定控件的数据绑定事件。

            //页上的每个控件都会发生 PreRender 事件。使用该事件对页或其控件的内容进行最后更改。

            if (!IsPostBack)
            {
                Master.SetContentTitle("我发起的流程");
                //InitData();
            }

            base.OnPreRender(e);

        }

        private void InitData()
        {
            this.CalendarExtender1.SelectedDate = DateTime.Today;
            this.CalendarExtender2.SelectedDate = DateTime.Today;
            this.CalendarExtender3.SelectedDate = DateTime.Today;
            this.CalendarExtender4.SelectedDate = DateTime.Today;

            gvMyInprocess.DataSource = null;
            gvMyInprocess.DataBind();
        }

        private void SearchAciton()
        {
        }

        protected void imbSearch_Click(object sender, ImageClickEventArgs e)
        {
            DateTime? submitStart = null;
            if (!string.IsNullOrEmpty(txtStartSubmit.Text))
                submitStart = DateTime.Parse(txtStartSubmit.Text);

            DateTime? submitEnd = null;
            if (!string.IsNullOrEmpty(txtEndSubmit.Text))
                submitEnd = DateTime.Parse(txtEndSubmit.Text);

            DateTime? closeStart = null;
            if (!string.IsNullOrEmpty(txtStartClose.Text))
                closeStart = DateTime.Parse(txtStartClose.Text);

            DateTime? closeEnd = null;
            if (!string.IsNullOrEmpty(txtEndClose.Text))
                closeEnd = DateTime.Parse(txtEndClose.Text);

            using (IInstanceApproval IAD = DALFactory.GetDAL<IInstanceApproval>())
            {
                //List<InstanceApproval> GetApprovedItems(int userId, string recordId = "", int? submitterId = null, string processName = "", DateTime? dtStart = null, DateTime? dtEnd = null);
                List<InstanceApproval> MyWork = IAD.GetRequestItems(YBPSession.Instance.CurrentUser.Id, txtRecoldId.Text, YBPSession.Instance.CurrentUser.Id, txtProcessName.Text, submitStart, submitEnd, closeStart, closeEnd);
                if (MyWork != null && MyWork.Count > 0)
                {
                    List<InstantView> MyWorkView = PageDataBandHelper.GetInstantView(MyWork);
                    gvMyInprocess.DataSource = MyWorkView;
                    gvMyInprocess.DataBind();
                }
                else
                {
                    gvMyInprocess.DataSource = null;
                    gvMyInprocess.DataBind();
                }
            }
        }

        protected void gvMyInprocess_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "ViewDetail")
            {
                Response.Redirect(@"~/Pages/View.aspx?RecordId=" + e.CommandArgument.ToString());
            }
        }
    }
}